/*****************************************************************************
 *
 *                      HUSONG PROPRIETARY INFORMATION
 *
 *          The information contained herein is proprietary to HUSONG
 *           and shall not be reproduced or disclosed in whole or in part
 *                    or used for any design or manufacture
 *              without direct written authorization from HUSONG.
 *
 *            Copyright (c) 2015 by HUSONG.  All rights reserved.
 *
 *****************************************************************************/
package me.send.data.service.mapper.provider;

import java.util.Map;

import me.send.business.base.Pager;


/**
 * @author maxmin
 *
 * @date 2015年9月24日 上午11:40:46
 */
public class AdvertProvider {
	
	public String getAdvertList(Map<String,Object> param){
		if (param!=null) {
			StringBuffer sb = new StringBuffer();
			Pager pager = (Pager)param.get("page");
			String cityName = (String)param.get("cityName");
			String startTime = (String)param.get("startTime");
			String endTime = (String)param.get("endTime");
			String keyCode = (String)param.get("keyCode");
			String cn = (String)param.get("cn");
			sb.append("SELECT * FROM advert WHERE isdelete=0 ");
			if (cn!=null && !"".equals(cn)) {
				if ("allCity".equals(cn)) {
					sb.append(" AND 1=1 ");
				}else {
					sb.append(" AND cityname ='").append(cn).append("' ");
					
				}
			}
			if (cityName!=null && cityName!="") {
				sb.append(" AND cityname LIKE'%").append(cityName).append("%'");
			}
			if (startTime!=null && startTime!="") {
				sb.append(" AND starttime >'").append(startTime).append("'");
			}
			if (endTime!=null && endTime!="") {
				sb.append(" AND endTime >'").append(endTime).append("'");
			}
			if (keyCode!=null && keyCode!="") {
				sb.append(" AND descption LIKE'%").append(keyCode).append("%'");
			}
			if (pager!=null) {
				sb.append("LIMIT ").append(pager.getStart()).append(",").append(pager.getRows());
			}
			return sb.toString();
		}
		return null;
	}
	
	public String getAdvertCount(Map<String,Object> param){
		if (param!=null) {
			StringBuffer sb = new StringBuffer();
			String cityName = (String)param.get("cityName");
			String startTime = (String)param.get("startTime");
			String endTime = (String)param.get("endTime");
			String keyCode = (String)param.get("keyCode");
			String cn = (String)param.get("cn");
			sb.append("SELECT COUNT(1) FROM advert WHERE isdelete=0 ");
			if (cn!=null && !"".equals(cn)) {
				if ("allCity".equals(cn)) {
					sb.append(" AND 1=1");
				}else {
					sb.append(" AND cityname ='").append(cn).append("' ");
				}
			}
			if (cityName!=null && cityName!="") {
				sb.append(" AND cityname LIKE'%").append(cityName).append("%'");
			}
			if (startTime!=null && startTime!="") {
				sb.append(" AND starttime >'").append(startTime).append("'");
			}
			if (endTime!=null && endTime!="") {
				sb.append(" AND endTime >'").append(endTime).append("'");
			}
			if (keyCode!=null && keyCode!="") {
				sb.append(" AND descption LIKE'%").append(keyCode).append("%'");
			}
			return sb.toString();
		}
		return null;
	}
}
